package com.gitee.neuray.security.par.parworkclock.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gitee.neuray.security.common.msg.ObjectRestResponse;
import com.gitee.neuray.security.common.msg.TableResultResponse;
import com.gitee.neuray.security.common.rest.BaseController;
import com.gitee.neuray.security.common.util.ExcelUtils;
import com.gitee.neuray.security.common.util.Query;
import com.gitee.neuray.security.par.parworkclock.vo.ParworkclockVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.gitee.neuray.security.par.parworkclock.biz.ParworkclockBiz;
import com.gitee.neuray.security.par.parworkclock.vo.ParworkclockPageExcelVo;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * 测试代码生成
 *
 * @author dev
 * @email ${email}
 * @date 2020-08-27 17:12:29
 */
@RestController
@RequestMapping("parworkclock")
public class ParworkclockController extends BaseController<ParworkclockBiz, ParworkclockVo> {
    @Autowired
    private ParworkclockBiz parworkclockBiz;


    /**
     * 分页获取列表
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "queryPage", method = RequestMethod.GET)
    public TableResultResponse queryPage(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        return parworkclockBiz.page(query);
    }

    @RequestMapping(value = "export", method = RequestMethod.GET)
    public void export(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
        Query query = new Query(params);
        List data = parworkclockBiz.nopage(query);
        List<ParworkclockPageExcelVo> execlData = JSONArray.parseArray(JSONObject.toJSONString(data), ParworkclockPageExcelVo.class);
        ExcelUtils.export(response, "测试代码生成", execlData, ParworkclockPageExcelVo.class);
    }

    /**
     * 插入数据
     *
     * @param parworkclockVo
     * @return
     */
    @PostMapping(value = "insert")
//    @RequestMapping(value = "insert" ,method = RequestMethod.POST)
    public ObjectRestResponse insert(@RequestBody ParworkclockVo parworkclockVo) {
        parworkclockBiz.insertSelective(parworkclockVo);
        return new ObjectRestResponse().rel(true);
    }

    /**
     * @param params
     * @return
     */
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public TableResultResponse list(@RequestParam Map<String, Object> params) {
        Query query = new Query(params);
        return parworkclockBiz.list(query);
    }

}
